<template>
  <div class="container">
    <div class="login-container">
      <div class="account-top">
        <div class="account-top-logo"><img src="../assets/logo.png" alt=""></div>
        <div class="account-top-desc">全栈中台/微服务框架解决方案</div>
      </div>
      <Form id="loginForm" ref="loginForm" :model="form" :rules="rules">
        <FormItem prop="userName">
          <Input prefix="ios-contact-outline" size="large" v-model="form.userName" placeholder="请输入用户名" clearable/>
        </FormItem>
        <FormItem prop="userPassword">
          <Input prefix="ios-lock-outline" type="password" size="large" v-model="form.userPassword" placeholder="请输入密码" @on-enter="handleSubmit()" clearable/>
        </FormItem>
        <FormItem>
          <Button @click="handleSubmit" size="large" type="primary" long :loading="submitStatus">登录</Button>
        </FormItem>
      </Form>
      <span class="foorter-copyright">Copyright © {{new Date().getFullYear()}} RYH</span>
    </div>
  </div>
</template>


<script>
export default {
  data() {
    return {
      submitStatus: false,
      form: {},
      rules: {
        userName: { required: true, message: "用户名不能为空", trigger: "change,blur" },
        userPassword: { required: true, message: "密码不能为空", trigger: "change,blur" }
      },
    };
  },
  methods: {
    handleSubmit() {
      this.$refs.loginForm.validate((valid) => {
        if (valid) {
          this.submitStatus = true;
          this.$store.dispatch("user/login", this.form).then((res) => {
            this.$router.push("/");
          }).finally(()=>{this.submitStatus = false;});
        }
      });
    },
  },
};
</script>

<style scoped lang="less">
.container {
  height: 100%;
  background-image: url("../assets/login.png");
  background-size: cover;
  background-repeat: no-repeat;
  .login-container {
    width: 390px;
    max-width: 90%;
    margin: 0 auto;
    padding: 80px 0 0;
    button {
      margin-top: 10px;
      font-size: 16px;
    }
    .account-top-logo {
      width: 100%;
      display: block;
      margin: 0 auto;
      user-select: none;
      pointer-events: none;
      img {
        width: 70%;
        margin: 0 auto;
        display: block;
      }
    }
    .account-top-desc {
      font-size: 14px;
      color: #d5d5d5;
      text-align: center;
      padding: 10px 0 30px;
    }
    .foorter-copyright {
      color: #fff;
      text-align: center;
      position: absolute;
      left: 50%;
      bottom: 30px;
      transform: translateX(-50%);
    }
  }
}
</style>